﻿Public Class FutureCruises
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Private Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FormView1.ItemInserted
        If e.Exception Is Nothing Then
            Me.GridView2.DataBind()
        End If
    End Sub

    Private Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
        Dim fileupload1 As FileUpload = CType(Me.FormView1.FindControl("fileupload1"), FileUpload)



        If fileupload1.HasFile = True Then
            '  fileupload1.SaveAs(MapPath(fileupload1.FileName))
            Dim filepath As String = fileupload1.PostedFile.FileName

            fileupload1.PostedFile.SaveAs(Server.MapPath(".\UserPictures\") & filepath)
            Session("fileupload") = "~\UserPictures\" & fileupload1.FileName

        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        If TextBox2.Text <> "" Then
            Dim cost As Integer
            Try

                ' Convert textbox to integer
                cost = Convert.ToInt32(TextBox2.Text)
            Catch ex As Exception
                cost = 0
            End Try

            Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\CruisesDB.accdb;Persist Security Info=True"
            Dim SqlString As String = "SELECT futureCruisesTable.CId, futureCruisesTable.CTitle, futureCruisesTable.CDate, futureCruisesTable.CTime, futureCruisesTable.CSeason, futureCruisesTable.CCountry, futureCruisesTable.CCity, futureCruisesTable.CPlace, futureCruisesTable.CCoste, futureCruisesTable.CDescription, futureCruisesTable.CThumbnail, futureCruisesTable.Cuserid, futureCruisesTable.CCreatedate, Users.Uname, Users.UId, Users.[Personal Picture] FROM (futureCruisesTable INNER JOIN Users ON futureCruisesTable.Cuserid = Users.UId)  WHERE        (CTitle LIKE '%" & TextBox2.Text & "%') OR                          (CSeason LIKE '%" & TextBox2.Text & "%') OR                         (CCountry LIKE '%" & TextBox2.Text & "%') OR                          (CCity LIKE '%" & TextBox2.Text & "%') OR                          (CPlace LIKE '%" & TextBox2.Text & "%') OR                          (CCoste =" & cost & ")"

            SqlDataSourceCruisesTable.SelectCommand = SqlString
            'view search result in the gridview
            GridView2.DataBind()
        End If
    End Sub
End Class